<!--
*@description 
*@fileName 机构管理
*@author wxl
*@date 2025/06/06 15:29:11
!-->
<template>
   <div class="vue-box cdf">
      <div class="search-card">
         <div class="search-body">
            <el-form :inline="true" :model="searchData">
               <el-form-item label="医疗机构名称">
                  <el-input v-model="searchData.fixmedins_name" placeholder="请输入机构名称"  />
               </el-form-item>
               <el-form-item label="医疗机构编码">
                  <el-input v-model="searchData.fixmedins_code" placeholder="请输入机构编码"  />
               </el-form-item>
               <el-form-item label="负责人">
                  <el-input v-model="searchData.Director" placeholder="请输入负责人姓名"  />
               </el-form-item>
               <el-form-item>
                  <el-button class="btn" type="primary" @click="onSearch">搜索</el-button>
                  <el-button type="default" plain icon="el-icon-Refresh" @click="sa.f5CurrView()">重置</el-button>
               </el-form-item>
            </el-form>
         </div>
      </div>
      <div class="c-card flex1 table-box">
         <div class="margin-bottom">
            <el-button class="btn" type="primary" :icon="Plus" size="small" @click="add">新增</el-button>
            <el-button class="btn" type="danger" :icon="Delete" size="small" @click="onDelete()">删除</el-button>
         </div>
         <com-table rowKey="MedinsinfoId" :tableData="tableData" :tableCfg="tableCfg" :pagin="searchData" showSelection showIndex showOperation operationWidth="170"
         @handleSelectionChange="handleSelectionChange" @handleCurrentChange="handleCurrentChange" @handleSizeChange="handleSizeChange">
            <!-- <template #dr_code="{row}">
               <span class="fs16">*******</span>
               <el-button text class="copy-btn" :icon="CopyDocument"  type="info" @click="sa.copyText(row.dr_code)">复制</el-button>
            </template> -->
            <template #operation="{row}">
               <el-button type="primary" size="small" text @click="get(row)">查看</el-button>
               <el-button style="margin-left: 0;" type="primary" size="small" text @click="update(row)">编辑</el-button>
               <el-button style="margin-left: 0;" type="danger" size="small" text @click="onDelete(row)">删除</el-button>
            </template>
         </com-table>
      </div>
   </div>
</template>
<script setup name="goods-list">
import { reactive,onMounted, ref } from 'vue'
// import {useRouter} from 'vue-router'
import comTable from '@/sa-frame/com/table/table.vue'
import dicts from '@/utils/dict.js'
import {
   Plus,Delete,CopyDocument
} from '@element-plus/icons-vue'
const searchData = reactive({
   pageindex: 0,
   pagesize: 10,
   total: 0
})

const tableCfg = ref([
  {
    label: '医疗机构名称',
    prop: 'fixmedins_name',
    width: 200,
  },
  {
    label: '医疗机构编码',
    prop: 'fixmedins_code',
    width: 200,
  },
  {
    label: '医疗服务机构类型',
    prop: 'fixmedins_type',
    type: 'dict',
    dictName: 'fixmedins_type',
    tag: true,
  },
  {
    label: '负责人姓名',
    prop: 'Director',
  },
  {
    label: '负责人手机号',
    prop: 'fixmedins_phone'
  },
  {
    label: '医师数量',
    prop: ''
  }
])

const tableData = ref([])
// 已选择行
const selectedRows = ref([])

// 组件加载时触发
onMounted(() => {
    f5();
})

// 搜索
function onSearch() {
   searchData.pageindex = 0
   f5()
}

// ------------------ 查找数据 ------------------
const f5 = function () {
  let params = searchData
  sa.ajax('/api/webPresAdmin/medinsinfoList', params, function (res) {
    tableData.value = res.data // 数据
    searchData.total = Number(res.totalItems)
  })
}
// 增加 
const add = function () {
    sa.showModel('新增机构', import('./org-edit.vue'));
}
// 修改
const update = function (data) {
    sa.showModel('修改机构', import('./org-edit.vue'), { id: data.MedinsinfoId });
};
// 详情 
const get = function (data) {
    sa.showModel('查看详情', import('./org-info.vue'), { id: data.MedinsinfoId });
};
// 删除
function onDelete(row) {
   const deleteData = row ? [row] : selectedRows.value
   if(!row && !deleteData.length) {
      sa.alert('请选择要删除的行')
      return
   }
   const MedinsinfoIds = deleteData.map(item => item.MedinsinfoId).join(',')
   sa.confirm('确定要删除选中的数据？', function() {

      sa.ajax('/api/webPresAdmin/delMedinsinfo', {
         MedinsinfoId: MedinsinfoIds
      }, function(res) {
         if(res.code == '1') {
            sa.alert(res.msg)
            f5()
         }
      })
   })
}
// 表格页码切换
function handleCurrentChange(pageindex) {
   searchData.pageindex = pageindex
   f5()
}
// 表格size修改
function handleSizeChange(pagesize) {
   searchData.pagesize = pagesize
   f5()
}
// 表格行选择
function handleSelectionChange(val) {
  console.log('handleSelectionChange',val)
  selectedRows.value = val
} 
// 对外开放函数 
defineExpose({f5})
</script>
<style lang="scss" scoped>
.copy-btn{
   border-left: 1px solid #ccc;
   color: #999;
   font-size: 12px;
   padding-left: 15px;
   margin-left: 15px;
   cursor: pointer;
   border-radius: 0!important;
   height: 20px;
}
</style>
